const dbMod = require('../db/dbMod');


function getStatus (userID, callback) {
    let sql = 'SELECT userPower FROM account WHERE userID = ?';
    dbMod.query(sql, [userID], (result) => {
        console.log('查询结果');
        var statusResult = eval(result);
        callback(statusResult);
    })
}

function setStatusBlock (userID, callback) {
    let sql = 'UPDATE account SET userStatus = 0 WHERE userID = ?';
    dbMod.query(sql, [userID], (result) => {
        console.log('封禁成功');
        var block = "封禁成功";
        callback(block);
    })
}

function setStatusUnblock (userID, callback) {
    let sql = 'UPDATE account SET userStatus = 1 WHERE userID = ?';
    dbMod.query(sql, [userID], (result) => {
        console.log('解封成功');
        var unblock = "解封成功";
        callback(unblock);
    })
}

function setPowerUp (userID, callback) {
    let sql = 'UPDATE account SET userPower = 1 WHERE userID = ?';
    dbMod.query(sql, [userID], (result) => {
        console.log('提权成功');
        var powerup = "提权成功";
        callback(powerup);
    })
}

function setPowerDown (userID, callback) {
    let sql = 'UPDATE account SET userPower = 0 WHERE userID = ?';
    dbMod.query(sql, [userID], (result) => {
        console.log('降权成功');
        var powerdown = "降权成功";
        callback(powerdown);
    })
}

function getUserList (userID, callback) {
    let sql = 'SELECT account.userID, userName, account.userAccount, userStatus, userPower FROM user INNER JOIN account ON user.userID = account.userID';
    dbMod.query(sql, [userID], (result) => {
        console.log('查询结果');
        var userList = eval(result);
        console.log(userList)
        callback(userList);
    })
}


exports.getStatus = getStatus
exports.setStatusBlock = setStatusBlock
exports.setStatusUnblock = setStatusUnblock
exports.setPowerUp = setPowerUp
exports.setPowerDown = setPowerDown
exports.getUserList = getUserList